<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\Common\Constants\StatusConstants;
use App\CustHub\Model\ChOpSchemeRobot;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Mine\Abstracts\AbstractMapper;
use Mine\MineModel;

class ChOpSchemeRobotMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChOpSchemeRobot::class;
    }

    /**
     * 获取机器人配置方案
     * @param mixed $robotId
     * @param mixed $type
     * @return \class-string[]|Builder[]|Collection|ChOpSchemeRobot[]
     */
    public function findRobotScheme(mixed $robotId,mixed $type): array|Collection
    {
        return $this->model::query()
            ->with(['scheme'=>function ($query) {
                $query->where('status',StatusConstants::ENABLE);
            }])
            ->where('robot_id',$robotId)
            ->where('type',$type)
            ->where('status',StatusConstants::ENABLE)
            ->get();
    }

    /**
     * @param mixed $schemeId
     * @param int $type
     * @return bool|int|mixed|null
     * @throws \Exception
     */
    public function deleteBySchemeIdAndType(mixed $schemeId,int $type): mixed
    {
        return $this->model::query()
            ->where('scheme_id',$schemeId)
            ->where('type',$type)
            ->delete();
    }
}